function initBreaker(){
//	按时间分类。时间轴为时间。具体分为历史平均，2012等。这是一个map的key
//	x轴为地区列表。每个key对应一组数据，[地区的年平均时间]，点击出现地区的12个月平均时间
//	我拿到的应该是 各个地区的各个动作。先分成地区map。每个地区map遍历得出地区各时间。有一个按照月份分类的map。有一个按照年份分类的map
	var breakerInitData = [];
	var areas = ['超高压公司',
	             '调峰调频公司',
	             '广东电网',
	             '广州电网',
	             '深圳电网',
	             '广西电网',
	             '云南电网',
	             '贵州电网',
	             '海南电网'];

//	年份map key为年份   value为[所有的动作]
	var yearBreakerMap = new Map();
//  年份map key为年份  value为{'1月':[所有的动作],'2月':[所有的动作]}
	var monthBreakerMap = new Map();
//	地域map key为地域  value为 [所有的动作]   
	var areaBreakerMap = new Map();
	var years = [];
	var months = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];
	var maxLag = 0;
	var aveLag = 0;
//	key是年份，value是[[area,20],[area,30],[area,40]]
	var breakerChart3Data = new Map();
//	属性名是各个公司，各个属性的值是 map。map里key是年份，value是[['1月',20],['2月',25],['',45]]
//	对于年份：历史总计，value是[['2012年',12],[],[],[]]
	var breakerChart4Data = {
			'超高压公司': new Map(),
			'调峰调频公司': new Map(),
			'广东电网': new Map(),
			'广州电网': new Map(),
			'深圳电网': new Map(),
			'广西电网': new Map(),
			'云南电网': new Map(),
			'贵州电网': new Map(),
			'海南电网': new Map()
	};
//	key为year value{['1月',max,ave],['2月',max,ave]} 若为历史总计 {['2012年',max,ave],[]} 
	var breakerChart5Data = new Map();
//	key为year value[['[0ms,5ms]',20],['[5ms,10ms]',50],['[10ms,15ms]',80]]
	var pieData = new Map();
	var selectedArea = "";
	var selectedYear = "";
	var selectedYearIndex = 0;

	var BreakerPie1 = null;
	var BreakerChart3 = null;
	var BreakerChart4 = null;
	var BreakerChart5 = null;
	var BreakerTimeLine1 = null;
	
	initBreakerInitData();
	function initBreakerInitData(){
		var startDate = new Date();
		startDate.setFullYear(2010, 0, 1);
		var endDate = new Date();
		endDate.setFullYear(2016, 11, 30);

		var createData = function(lagStart,lagEnd,dataNum){
			for(var i = 0;i<dataNum;i++){
				var area = areas[i%areas.length];
				var date = new Date(startDate.getTime()+ Math.floor((endDate - startDate)*Math.random()));
				var timelag = lagStart + Math.floor((lagEnd-lagStart)*Math.random());
				breakerInitData.push([area,date,timelag]);
			}
		};

		//百分之0.66在0-10之间
		createData(1,11,66);
		//百分之2.47在10-20之间
		createData(11,21,247);
		//百分之23.52在20-30之间
		createData(21,31,2352);
		//百分之59.70在30-40之间
		createData(31,41,5970);
		//百分之10.86在40-50之间
		createData(41,51,1086);
		//百分之2.30在50-60之间
		createData(51,61,230);
		//百分之0.33在60-70之间
		createData(61,71,33);
		//百分之0.16在70-80之间
		createData(71,80,16);
		breakerInitData.sort(compare);
		initBreakerMap();
	}
	function compare(obj1,obj2){
		if(obj1[1]<obj2[1]){
			return -1;
		}else{
			return 1;
		}
	}
	function initBreakerMap(){
		var sum = 0;
		var num = 0;
		//取得年份列表
		for(var i in breakerInitData){
			var breaker = breakerInitData[i];
			var time = new Date(breaker[1]);
			var area = breaker[0];
			var lag = Number(breaker[2]);
			
			sum = sum + lag;
			num++;
			if(lag > maxLag){
				maxLag = lag;
			}

			var yearvalue = yearBreakerMap.get(time.getFullYear()+"年");
			if(!yearvalue){
				yearvalue = [];
				yearBreakerMap.put(time.getFullYear()+"年",yearvalue);
			}
			yearvalue.push(breaker);
			
			var monthvalue = monthBreakerMap.get(time.getFullYear()+"年");
			if(!monthvalue){
				monthvalue = {'1月':[],'2月':[],'3月':[],'4月':[],'5月':[],'6月':[],
						'7月':[],'8月':[],'9月':[],'10月':[],'11月':[],'12月':[]
				};
				monthBreakerMap.put(time.getFullYear()+"年",monthvalue);
			}
			monthvalue[time.getMonth()+1+"月"].push(breaker);
			
			var areavalue = areaBreakerMap.get(area);
			if(!areavalue){
				areavalue = [];
				areaBreakerMap.put(area, areavalue);
			}
			areavalue.push(breaker);
			
		}
		num = num==0?1:num;
		aveLag = (sum/num).toFixed(2);
		years = yearBreakerMap.keys;
		years.unshift(years[0]+"~"+years[years.length-1]);
		selectedArea = areas[0];
		selectedYear = years[0];
		selectedYearIndex = 0;
		initBreakerChart5Data();
		initBreakerPie1Data();
		initBreakerChart3Data();
		initBreakerChart4Data();
		initBreakerTimeLine1();
	}
	function initBreakerChart5Data(){
		var yearsData = [];
		breakerChart5Data.put(years[0],yearsData);
		var i=1;
		for(i=1;i<years.length;i++){
			var year = years[i];
			//求年平均
			var yearBreakers = monthBreakerMap.get(year);
			var yearSum = 0;
			var yearNum = 0;
			var yearMax = 0;
			var yearData = [];
			breakerChart5Data.put(year, yearData);
			var j="";
			for(j in yearBreakers){
				var month = j;
				var monthBreakers = yearBreakers[month];
				//求月平均
				var sum = 0;
				var num = 0;
				var max = 0;
				var z=0;
				for(z=0;z<monthBreakers.length;z++){
					var breaker = monthBreakers[z];
					var lag = Number(breaker[2]);
					if(lag > max){
						max = lag;
					}
					sum = sum + lag;
					num++;
					
					if(lag > yearMax){
						yearMax = lag;
					}
					yearSum = yearSum + lag;
					yearNum++;
				}
				num = num==0?1:num;
				yearData.push([month,max,(sum/num).toFixed(2)]);
			}
			yearNum = yearNum==0?1:yearNum;
			yearsData.push([year,yearMax,(yearSum/yearNum).toFixed(2)]);
		}
		initBreakerChart5();
	}
	function initBreakerPie1Data(){
		var i=0;
		var legendlist = [];
		for(i=0;i<=maxLag/10;i++){
			i=Number(i);
			legendlist.push({
				min:i*10,
				max:(i+1)*10,
				num:0
			});
		}
		var tempData = new Map();
		var tempSumData = new Map();
		for(i=1;i<years.length;i++){
			var year = years[i];
			var pieyear = [];
			var tempyear = legendlist.concat();
			pieData.put(year, pieyear);
			tempData.put(year,tempyear);

			var j=0;
			var ybreakers = yearBreakerMap.get(year);
			for(j=0;j<ybreakers.length;j++){
				var breaker = ybreakers[j];
				var lag = Number(breaker[2]);
				tempyear[Math.floor(lag/10)].num ++;
			}
			j=0;
			for(j=0;j< tempyear.length;j++){
				var temp = tempyear[j];
				var s = '['+temp.min+'ms,'+temp.max+'ms]';
				pieyear.push([s,temp.num]);

			}
		}

		pieData.each(function(index,key,value){
			var i =0;
			for(i=0;i<value.length;i++){
				var item = value[i][0];
				var num = Number(value[i][1]);
				var tempSum = tempSumData.get(item);
				if(!tempSum){
					tempSum = num;
				}else{
					tempSum = Number(tempSum) + num;
				}
				tempSumData.put(item,tempSum);
			}
		});
		//历史总计
		var list = [];
		tempSumData.each(function(index,key,value){
			list.push([key,value]);
		});
		pieData.put(years[0], list);
		initBreakerPie1();
	}
	function initBreakerChart3Data(){
		//第一个是总计
		var areaLags = []; 
		var valueMap = new Map();
		var i = 0;
		for(i in areas){
			valueMap.put(areas[i], [0,0]);
		}
		i=0;
		for(i in breakerInitData){
			var area = breakerInitData[i][0];
			var lag = breakerInitData[i][2];
			var sum = valueMap.get(area)[0];
			var num = valueMap.get(area)[1];
			valueMap.put(area,[sum+lag,num+1]);
		}
		i=0;
		for(i in areas){
			var sum = valueMap.get(areas[i])[0];
			var num = valueMap.get(areas[i])[1] == 0? 1:valueMap.get(areas[i])[1];
			areaLags.push([areas[i],(sum/num).toFixed(2)]);
		}
		breakerChart3Data.put(years[0], areaLags);
		//各个年份
		for(var j=1;j < years.length;j++){
			var areaLags = [];
			var yearsdata = yearBreakerMap.get(years[j]);
			var valueMap = new Map();
			i = 0;
			for(i in areas){
				valueMap.put(areas[i], [0,0]);
			}
			i=0;
			for(i in yearsdata){
				var area = yearsdata[i][0];
				var lag = yearsdata[i][2];
				var sum = valueMap.get(area)[0];
				var num = valueMap.get(area)[1];
				valueMap.put(area,[sum+lag,num+1]);
			}
			i=0;
			for(i in areas){
				var sum = valueMap.get(areas[i])[0];
				var num = valueMap.get(areas[i])[1] == 0? 1:valueMap.get(areas[i])[1];
				areaLags.push([areas[i],(sum/num).toFixed(2)]);
			}
			breakerChart3Data.put(years[j], areaLags);
		}
		initBreakerChart3();
	}
	function initBreakerChart4Data(){
		var area=0;
		for(area in breakerChart4Data){
			//每个地域的map:key为年份，value为[['1月',25],['2月',20]]
			var yearMonthValueMap = breakerChart4Data[area];
			var yearMonthBreakerMap = new Map();
			var breakers = areaBreakerMap.get(area);
			var j=0;
			for(j in years){
				yearMonthValueMap.put(years[j],[]);
				yearMonthBreakerMap.put(years[j],{
					'1月':[],
					'2月':[],
					'3月':[],
					'4月':[],
					'5月':[],
					'6月':[],
					'7月':[],
					'8月':[],
					'9月':[],
					'10月':[],
					'11月':[],
					'12月':[]
				});
			}
			j=0;
			for(j in breakers){
				var breaker = breakers[j];
				var time = new Date(breaker[1]);
				var lag = breaker[2];
				yearMonthBreakerMap.get(time.getFullYear()+"年")[time.getMonth()+1+"月"].push(lag);
			}
			for(j=1;j<years.length;j++){
				var year = years[j];
				var monthAves = yearMonthValueMap.get(year);
				var monthBreakers = yearMonthBreakerMap.get(year);
				for(var month in monthBreakers){
					var mbreakers =  monthBreakers[month];
					var i=0;
					var sum = 0;
					var num = 0;
					for(i in mbreakers){
						sum = sum + mbreakers[i];
						num++;
					}
					num = num == 0? 1:num;
					monthAves.push([month,(sum/num).toFixed(2)]);
				}
			}
			//添加各个年份的历史总计
			//历史总计：[[2012年,3],[],[]]
			for(i=1;i<years.length;i++){
				var sum = 0;
				var num = 0;
				for(j=0;j< months.length;j++){
					//[[1月，20],[],[]]
					var monthAves = yearMonthValueMap.get(years[i]);
					var value = Number(monthAves[j][1]);
					sum = sum + value;
					if(value!=0){
						num++;
					}
				}
				if(num == 0){
					num =1;
				}
				yearMonthValueMap.get(years[0]).push([years[i],(sum/num).toFixed(2)]);
			}
		}

		initBreakerChart4();
	}
	function initBreakerChart3(){
		var bar = new TimeBar('breakerChart3');
		bar.setxAxis(areas);
		bar.setxAxisTitle("公司");
		bar.setyAxisTitle("ms");
		var i=0;
		for(i in years){
			var year = years[i];
			bar.setTimePoint(year);
			bar.setTimePointTitle(year+"各单位断路器动作时间");
			var yaxis = [];
			var j=0;
			var yaxisData = breakerChart3Data.get(year);
			for(j in yaxisData){
				yaxis.push(yaxisData[j][1]);
			}
			bar.setTimePointyAxis(yaxis);
			bar.setTimePointyAxisName("断路器动作时间");
		}
		bar.setSelectedIndex(selectedYearIndex);
		bar.setZoomTool(false);
		var option = bar.getOption();
		option.baseOption.timeline.show = false;
		option.baseOption.title.left = "center";
		option.baseOption.title.textStyle.fontWeight = "normal";
		option.baseOption.title.textStyle.fontSize = 16;
		option.baseOption.legend.show = false;
		bar.show();

		bar.getChart().on('click',function(params){
			if(areas.indexOf(params.name) != -1){
				selectedArea = params.name;
				initBreakerChart4();
			}
		});
		BreakerChart3 = bar.getChart();
		return BreakerChart3;
	}

	function initBreakerChart4(){
		var data = breakerChart4Data[selectedArea];
		var line = new TimeLineChart('breakerChart4');
		line.setyAxisTitle("ms");
		var i=0;
		for(i=0;i< years.length;i++){
			var year = years[i];
			line.setTimePoint(year);
			line.setTimePointTitle(selectedArea+year+"断路器动作时间");
			var yaxis = [];
			var j=0;
			var yaxisData = data.get(year);
			for(j in yaxisData){
				yaxis.push(yaxisData[j][1]);
			}
			line.setTimePointyAxis(yaxis);
			line.setTimePointyAxisName("断路器动作时间");
			if(i == 0){
				line.setTimePointxAxis(years.slice(1));
				line.setTimePointxAxisTitle("年份");
			}else{
				line.setTimePointxAxis(months);
				line.setTimePointxAxisTitle("月份");
			}
		}
		line.setSelectedIndex(selectedYearIndex);
		line.setZoomTool(false);
		var option = line.getOption();
		option.baseOption.timeline.show = false;
		option.baseOption.title.right = "center";
		option.baseOption.title.textStyle.fontWeight = "normal";
		option.baseOption.title.textStyle.fontSize = 16;
		option.baseOption.legend.show = false;
		line.show();

		BreakerChart4 = line.getChart();
		return BreakerChart4;
	}
	function initBreakerPie1(){
		var pie = new TimePie("breakerPie1");
		var i=0;
		for(i=0;i<years.length;i++){
			pie.setTimePoint(years[i]);
			pie.setTimePointPie(pieData.get(years[i]));
			pie.setTimePointTitle(years[i]+"500kv系统断路器动作时间");
		}
		pie.setSelectedIndex(selectedYearIndex);
		var option = pie.getOption();
		option.baseOption.timeline.show = false;
		option.baseOption.title.left = "center";
		option.baseOption.title.textStyle.fontWeight = "normal";
		option.baseOption.title.textStyle.fontSize = 16;
		i=0;
		for(i=0;i<option.options.length;i++){
			option.options[i].series[0].startAngle = 180;
			option.options[i].series[0].center = ['40%','50%'];
		}
		pie.show();

		BreakerPie1 = pie.getChart();
		return BreakerPie1;
	}
	function initBreakerChart5(){
		var line = new TimeLineChart('breakerChart5');
		var i=0;
		for(i=0;i<years.length;i++ ){
			var year =  years[i];
			var yearData = breakerChart5Data.get(year);
			var maxList = [];
			var aveList = [];
			var xList = [];
			var j=0;
			for(j=0;j<yearData.length;j++){
				var data = yearData[j];
				xList.push(data[0]);
				maxList.push(data[1]);
				aveList.push(data[2]);
			}
			line.setTimePoint(year).setTimePointTitle(year+"500kv系统断路器平均动作时间")
				.setTimePointxAxis(xList)
				.setTimePointyAxis(maxList).setTimePointyAxisName("断路器最长动作时间").setyAxisTitle("ms")
				.setTimePointyAxis(aveList).setTimePointyAxisName("断路器平均动作时间")
				.setSelectedIndex(selectedYearIndex);
			
			line.getOption().baseOption.timeline.show = false;
			var options = line.getOption().options;
			var option = options[options.length-1];
			option.legend.show = false;
			option.title.right = "center";
			option.title.textStyle.fontWeight = "normal";
			option.title.textStyle.fontSize = 16;
		}
		line.setZoomTool(false).setRestore(false).setMagicType(false);
		line.show();
		
		BreakerChart5  = line.getChart();
		return BreakerChart5;
	}
	function initBreakerTimeLine1(){
		var timeline = new TimePie("breakerTimeLine1");
		var i=0;
		for(i=0;i<years.length;i++){
			timeline.setTimePoint(years[i]);
		}
		timeline.setToolbox(false);
		var option = timeline.getOption();
		option.baseOption.tooltip.show = false;
		option.baseOption.timeline.label.normal.interval = 0;
		timeline.show();
		BreakerTimeLine1 = timeline.getChart();
		BreakerTimeLine1.on("timelinechanged",function(params){
			selectedYearIndex = params.currentIndex;
			selectedYear = years[selectedYearIndex];
			BreakerChart3.setOption({
				baseOption:{
					timeline:{
						currentIndex:selectedYearIndex
					}
				}
			});
			BreakerChart4.setOption({
				baseOption:{
					timeline:{
						currentIndex:selectedYearIndex
					}
				}
			});
			BreakerChart5.setOption({
				baseOption:{
					timeline:{
						currentIndex:selectedYearIndex
					}
				}
			});
			BreakerPie1.setOption({
				baseOption:{
					timeline:{
						currentIndex:selectedYearIndex
					}
				}
			});
		});
		return timeline.getChart();
	}
	this.resizeChart = function(){
		BreakerPie1.resize();
		BreakerChart5.resize();
		BreakerChart4.resize();
		BreakerChart3.resize();
		BreakerTimeLine1.resize();
	};
}
